home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
pcr
/
pcr4_4.lha
/
DIST
/
threads
/
semc.c
< prev
next >
Wrap
C/C++ Source or Header
|
1989-04-03
|
3KB
|
132 lines
/* begincopyright
Copyright (c) 1988 Xerox Corporation. All rights reserved.
Use and copying of this software and preparation of derivative works based
upon this software are permitted. Any distribution of this software or
derivative works must comply with all applicable United States export
control laws. This software is made available AS IS, and Xerox Corporation
makes no warranty about the software, its performance or its conformity to
any specification. Any person obtaining a copy of this software is requested
to send their name and post office or electronic mail address to:
PCR Coordinator
Xerox PARC
3333 Coyote Hill Rd.
Palo Alto, CA
endcopyright */
/*
* semc.c
*
* Demers, Thu Dec 3 19:36:41 PST 1987
*/
#include <stdio.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/sem.h>
char *myname = "semc";
char *usage = "Usage: %s [-d(elete] [-q(uiet] [-s(earch fromid toid] semid ...\n";
main(argc,argv)
int argc;
char **argv;
{
int dflag = 0;
int sflag = 0;
int qflag = 0;
int sfrom = -1;
int sto = -1;
int id = -1;
int i;
myname = argv[0];
if( argc <= 1 ) {
fprintf(stderr, usage, myname);
exit(-1);
}
for( i = 1; i < argc; i++ ) {
char *a = argv[i];
if( strcmp(a, "-d") == 0 ) {
dflag = 1;
continue;
}
if( strcmp(a, "-q") == 0 ) {
qflag = 1;
continue;
}
if( strcmp(a, "-s") == 0 ) {
sflag = 1;
if( (i+2) >= argc ) {
fprintf(stderr, "%s: missing arg for -s\n", myname);
exit(-1);
}
i += 1; sfrom = atoi(argv[i]);
i += 1; sto = atoi(argv[i]);
if( (sfrom < 0) || (sto < sfrom) ) {
fprintf(stderr, "%s: bad args for -s (%s %s)\n",
myname, argv[i-1], argv[i]);
exit(-1);
}
continue;
}
if( a[0] == '-' ) {
fprintf(stderr, "%s: bad flag %s\n", myname, a);
exit(-1);
}
if( (id = atoi(a)) < 0 ) {
fprintf(stderr, "%s: bad shmid %s\n", myname, a);
continue;
}
(void) doit(id, !qflag, dflag, 0);
}
if( sflag ) {
while( sfrom <= sto ) {
doit(sfrom, !qflag, dflag, 1);
sfrom += 1;
}
}
}
doit(id, print, delete, searching)
int id;
int print, delete, searching;
{
struct semid_ds b;
int ans;
ans = semctl(id, 0, IPC_STAT, &b);
if( ans < 0 ) {
if( !searching ) {
fprintf(stderr, "%s: sem = %d", myname, id);
perror("");
}
return;
}
if( print ) {
printf("Semaphore %d:\n", id);
printf(" perm:\n");
printf(" uid: %d\n", b.sem_perm.uid);
printf(" gid: %d\n", b.sem_perm.gid);
printf(" cuid: %d\n", b.sem_perm.cuid);
printf(" cgid: %d\n", b.sem_perm.cgid);
printf(" mode: %o\n", b.sem_perm.mode);
printf(" seq: %d\n", b.sem_perm.seq);
printf(" key: %D\n", b.sem_perm.key);
printf(" base: %X\n", b.sem_base);
printf(" nsems: %d\n", b.sem_nsems);
printf(" otime: %s", ctime(&(b.sem_otime)));
printf(" ctime: %s", ctime(&(b.sem_ctime)));
fflush(stdout);
}
if( delete ) {
printf("Deleting semaphore %d ... ", id);
ans = semctl(id, 0, IPC_RMID, &b);
if( ans < 0 ) { perror(myname); return; }
printf("deleted.\n");
fflush(stdout);
}
}